# url：http://www.bjhospital.net/
# 用例1：搜索骨科—>点击搜索—>点击出来的第一个链接—>断言文本内容
"""
from selenium import webdriver
from selenium.webdriver.common.by import By
option = webdriver.EdgeOptions() # todo：Edge浏览器配置项
option.add_experimental_option("detach", True)# todo：浏览器不会自动关闭
driver = webdriver.Edge(options=option)
driver.implicitly_wait(10)#隐式等待10s
driver.get("http://www.bjhospital.net/")
driver.maximize_window()
driver.find_element(By.CLASS_NAME,'keyword').send_keys("骨科")
driver.find_element(By.CLASS_NAME,'btn').click()
driver.find_element(By.XPATH,"/html/body/div[4]/ul/li[1]/div[1]/h5/a").click()#复制XPATH定位
#driver.find_element(By.LINK_TEXT,"毕节市第一人民医院高值医用耗材网上阳光平台议价意向公开").click()#link TEXT定位
#driver.find_elements(By.TAG_NAME,'a')[8].click()#TAG NAME定位
win = driver.window_handles
driver.switch_to.window(win[-1])
TextAssertion = driver.find_element(By.XPATH,"/html/body/div[3]/div/div/article/h1").text #复制XPATH
assert TextAssertion == "毕节市第一人民医院高值医用耗材网上阳光平台议价意向公开"
print(driver.title)
driver.quit()
"""
"""
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

class Searchs:
    def __init__(self,driver):
        self.driver = driver
        self.driver.get("http://www.bjhospital.net/")
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)  # 隐式等待10s

    def inputO(self,text):
        #self.driver.find_element(By.CLASS_NAME,'keyword').send_keys(text)
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located((By.CLASS_NAME,'keyword'))).send_keys(text)

    def findinput(self):
        #self.driver.find_element(By.CLASS_NAME, 'btn').click()
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME,'btn')))[0].click()

    def Tagname1(self):
        #self.driver.find_elements(By.TAG_NAME, 'a')[8].click()
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located((By.TAG_NAME, 'a')))[
            8].click()
        win = self.driver.window_handles
        self.driver.switch_to.window(win[-1])

    def assertTextAssertion(self):
        #TextAssertion = self.driver.find_element(By.XPATH, "/html/body/div[3]/div/div/article/h1").text
        TextAssertion = WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located((By.XPATH, "/html/body/div[3]/div/div/article/h1"))).text
        assert TextAssertion == "毕节市第一人民医院高值医用耗材网上阳光平台议价意向公开"
        print(self.driver.title)  # 打印标题

    def quit(self):
        self.driver.quit()

if __name__ == '__main__':
    driver = webdriver.Edge()
    a = Searchs(driver)  # 实例化对象
    a.inputO("骨科")  # 输入骨科
    a.findinput()  # 点击搜索
    a.Tagname1()  # 点击第一个内容并切换句柄
    a.assertTextAssertion()  # 断言是否通过
    a.quit()  # 退出浏览器
"""